﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using SharedCongkak;

namespace Congkak
{
    public class CollectingState: GameState
    {
        TimeSpan addInterval = new TimeSpan(500);
        TimeSpan currentInterval = new TimeSpan();
        AbstractHole selectedHole;
        SeedQueue seedQueue;
        bool doneCollecting;

        public CollectingState(GameplayScreen gamePlay, AbstractHole selectedHole, SeedQueue seedQueue)
            :base(gamePlay)
        {
            this.selectedHole = selectedHole;
            this.seedQueue = seedQueue;

        }

        public override void Update(GameTime gameTime)
        {

            if (!doneCollecting)
            {
                currentInterval += gameTime.ElapsedGameTime;
                if (currentInterval > addInterval)
                {
                    Seed seed = selectedHole.GetAndRemoveSeed();
                    seedQueue.Add(seed);
                    if (selectedHole.NoOfSeeds == 0)
                        doneCollecting = true;
                    currentInterval -= addInterval;
                }
            }
            else
            {
                // change to sowing state
                gamePlay.ChangeGameState(new SowingState(gamePlay, selectedHole, seedQueue));
            }
        }
    }
}
